﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Lists
{
    public partial class Account
    {
        public static Account CurAccount;
        public static Account Login(string userName, string password)
        {
            string encryptedPwd = GeneralLibs.CommonLib.MaHoaMD5(password);
            return new DBDataContext(GeneralLibs.LocalSettings.ConnectString).Accounts.FirstOrDefault(p => p.AccountName == userName && p.Password == encryptedPwd);
        }

        public bool ChangePassword(string encryptedPwd)
        {
            if (this == null) return false;
            DBDataContext db = new DBDataContext(GeneralLibs.LocalSettings.ConnectString);
            Account changedAccount = db.Accounts.FirstOrDefault(p => p.AccountID == this.AccountID);
            changedAccount.Password = encryptedPwd;
            db.SubmitChanges();
            this.Password = changedAccount.Password;
            return true;
        }
    }
}
